package ModelLayer;

import java.util.ArrayList;

public class Owner {
	private String ownerName;
	private String address;
	private String phoneNumber;
	
	private ArrayList<Forest> ownerForest;
	
	//Constructor with parameters
	public Owner(String name, String address, String phoneNumber){
		this.ownerName = name;
		this.address = address;
		this.phoneNumber = phoneNumber;
		
		ownerForest = new ArrayList<Forest>();
	}
	
	//Get and set owner name
	public String getOwnerName() {
		return ownerName;
	}
	public void setOwnerName(String ownerName) {
		this.ownerName = ownerName;
	}
	//Get and set address
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	//Get and set phoneNumber
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	
	/**
	 * Add forest to owner
	 * @param Forest forest
	 * */
	public void addForest(Forest f){
		ownerForest.add(f);
	}
	/**
	 * Remove forest from owner
	 * @param String name
	 * */
	public void removeForest(String name){
		boolean search = false;
		int i = 0;
		Forest f = null;
		while(!search && i < ownerForest.size()){
			f = ownerForest.get(i);
			if(f.getName() == name){
				search = true;
			}else{
				i++;
			}
		}
		if(search){
			ownerForest.remove(i);
		}
	}
	/**
	 * Find a forest by its name
	 * @param String name
	 * @return Forest forest
	 * */
	public Forest findForest(String name){
		boolean search = false;
		int i = 0;
		Forest f = null;
		while(!search && i < ownerForest.size()){
			f = ownerForest.get(i);
			if(f.getName() == name){
				search = true;
			}else{
				i++;
			}
		}
		if(search){
			return ownerForest.get(i);
		}else{
			return null;
		}
	}
	/**
	 * Get all forests
	 * @return ArrayList<Forest>
	 * */
	public ArrayList<Forest> getAllForests(){
		return ownerForest;
	}
	
}
